home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac Power 1997 December
/
MACPOWER-1997-12.ISO.7z
/
MACPOWER-1997-12.ISO
/
AMUG
/
PROGRAMMING
/
Raven 1.2 Examples.sit
/
Raven 1.2 Examples
/
Skeleton
/
Source
/
Main.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1997-08-16
|
5KB
|
190 lines
/*
* File: Main.cpp
* Summary: The big enchilada.
* Written by: Jesse Jones
*
* Copyright ゥ 1996-1997 Jesse Jones. All Rights Reserved.
*
* Change History (most recent first):
*
* <2> 8/15/97 JDJ Added code to main to dump object heap info in
* non-debug, non-release builds.
* <1> 2/24/96 JDJ Created.
*/
#include <List.h>
#include <List.h>
#include <ZAppBootStrap.h>
#include <ZFloatingDesktop.h>
#include <ZGestalt.h>
#include <ZPreferences.h>
#include <ZStringUtils.h>
#if RAVEN_OPERATOR_NEW
#include <ZBestFitAllocator.h>
#include <ZMemoryHeap.h>
#include <ZNewAndDelete.h>
#include <ZSimpleAllocator.h>
#endif
#include "App.h"
// ===================================================================================
// class TBootStrap
// ===================================================================================
//---------------------------------------------------------------
//
// TBootStrap::DoEarlyInit
//
// This is called after the toolbox is initialized, but before
// static objects are constructed. You shouldn't have to do
// anything besides creating the object heap here. (Use OnBoot
// if you need to initialize other things).
//
//---------------------------------------------------------------
void TBootStrap::DoEarlyInit()
{
const long kInitialObjectHeapSize = 500*1024L; // ・・・ハadjust these numbers (using the Dump Object Heap command in the Debug menu)
const long kObjectHeapIncrementSize = 32*1024L;
const short kNumMasterPtrBlocks = 10;
for (short i = 1; i <= kNumMasterPtrBlocks; i++)
MoreMasters();
#if RAVEN_OPERATOR_NEW // on by default
ASSERT(gObjectHeap == nil);
TAllocator* alloc = new TBestFitAllocator(kInitialObjectHeapSize, kObjectHeapIncrementSize);
gObjectHeap = new TMemoryHeap(alloc);
#else
_prealloc_newpool(kInitialObjectHeapSize);
_set_newpoolsize(kObjectHeapIncrementSize);
_set_newnonptrmax(kObjectHeapIncrementSize/4);
#endif
}
#pragma mark -
// ===================================================================================
// class CMyBooter
// TAppBootStrap initializes some of the core Raven classes and checks to make
// sure the machine is capable of running your app.
// ===================================================================================
class CMyBooter : public TAppBootStrap {
typedef TAppBootStrap Inherited;
//-----------------------------------
// Initialization/Destruction
//
public:
virtual ~CMyBooter();
CMyBooter();
//-----------------------------------
// Inherited API
//
protected:
virtual void OnSystemNeeds(list<string, allocator<string> >& needs);
virtual void OnBoot();
};
//---------------------------------------------------------------
//
// CMyBooter::~CMyBooter
//
//---------------------------------------------------------------
CMyBooter::~CMyBooter()
{
}
//---------------------------------------------------------------
//
// CMyBooter::CMyBooter
//
//---------------------------------------------------------------
CMyBooter::CMyBooter()
{
mIdealDisplayMode = SDisplayMode(640, 480, 8);
}
//---------------------------------------------------------------
//
// CMyBooter::OnSystemNeeds
//
// If your app requires things that aren't on every machine (eg
// QuickDraw 3D, the Drag Manager, etc) add a test here. TBootStrap
// will popup a dialog listing all of the items that are missing
// from the user's machine.
//
//---------------------------------------------------------------
void CMyBooter::OnSystemNeeds(list<string, allocator<string> >& needs)
{
Inherited::OnSystemNeeds(needs);
// if (!UGestalt::hasDragMgr)
// needs.push_back(LoadAppString("the Drag Manager"));
}
//---------------------------------------------------------------
//
// CMyBooter::OnBoot
//
// This is the best place to initialize stuff.
//
//---------------------------------------------------------------
void CMyBooter::OnBoot()
{
Inherited::OnBoot();
// Aplications often have just a few block sizes that account
// for the bulk of their operator new allocations. You can
// speed up operator new by calling AddAllocator for these
// common sizes. (You can find the most used block sizes by
// using the "Dump Object Heap" command in the Debug menu).
gObjectHeap->AddAllocator(20, 800);
TFloatingDesktop::Init();
UPreferences::Init(LoadAppString("Skeleton Prefs"), 'SKEL');
}
#pragma mark -
//---------------------------------------------------------------
//
// Main
//
//---------------------------------------------------------------
void main()
{
CMyBooter booter;
booter.Boot();
{
CApplication theApp;
theApp.Run();
}
#if RAVEN_OPERATOR_NEW && !DEBUG && !RELEASE
// Object sizes can change in release builds. If they do the
// fixed allocators may need to be adjusted. To check for this
// you should run a non-debug, non-release version of the app.
gObjectHeap->DumpCommonBlocks();
gObjectHeap->DumpAllocatorCapacities();
#endif
}